package com.hdhere.core.util;

import org.springframework.core.env.Environment;

/**
 * Created by dus on 2018/11/3.
 */
public class EnvironmentHolder {

    private static Environment environment;

    public void setEnvironment(Environment environment) {

        EnvironmentHolder.environment = environment;
    }

    public static Environment getEnvironment() {

        if (environment == null) {
            environment = SpringUtils.getBean(Environment.class);
        }
        return environment;
    }

    public static boolean isProduct() {

        return "PROD".equalsIgnoreCase(getProfileName());
    }

    public static String getProfileName() {

        String mode = getEnvironment().getProperty("profile.mode");
        if (mode == null) {
            mode = getEnvironment().getProperty("spring.profiles.active");
        }
        return mode;
    }

    public static String getApplicationName() {

        return getEnvironment().getProperty("spring.application.name");
    }

    public static String getProjectVersion() {

        return getEnvironment().getProperty("project.version");
    }

    public static String getProperty(String key) {

        return getEnvironment().getProperty(key);
    }
}
